#include "FileTest.h"
#include <stdio.h>
#include <string.h>

/*
 * Created: 2/27/12; CGP
Command line argument: 1
a) Create a new file (opened for writing)
b) Close the file
c) List the file to make sure it appears in directory
d) Stop your test program from running

Command line argument: 2
e) Restart your test program
f) List the file to make sure it appears in directory
g) Delete the file
h) List the file to make sure it doesn't appear in directory
i) Stop your test program from running

Command line argument: 3
j) Restart your test program
k) List the file to make sure it still doesn't appear in directory
 */
#define strequ(A, B) (strcmp(A, B) == 0)

int main(int argc, char *argv[]) {
    int length;
    printf("Starting test...\n"); fflush(stdout);
    FileTest ft;
    const char *fileName1 = "X";
    File *f1;

    if (strequ(argv[1], "1")) {
        printf("Creating a file...\n");
        f1 = new File(fileName1, "w");

        if (! f1->Close()) {
            printf("ERROR: Could not close file\n");
        }
        delete f1;

        if (ft.dir->LookUp(fileName1) == NULL) {
            printf("ERROR: %s file is not present in directory\n", fileName1);
        }
    }

    if (strequ(argv[1], "2")) {
        if (ft.dir->LookUp(fileName1) == NULL) {
            printf("ERROR: %s file is not present in directory\n", fileName1);
        }

        if (! File::Delete(fileName1)) {
            printf("ERROR: Could not delete file: %s\n", fileName1);
        } else {
            printf("SUCCESS: It seems we were able to delete the file!\n");
        }

        if (ft.dir->LookUp(fileName1) != NULL) {
            printf("ERROR: %s file is present in directory after deletion\n", fileName1);
        }
    }

    if (strequ(argv[1], "3")) {
        if (ft.dir->LookUp(fileName1) != NULL) {
            printf("ERROR: %s file is present in directory after deletion\n", fileName1);
        }
    }
}





